fix: migrate MissingRequiredArgumentError imports to ocp_resources.exceptions#2657
fix: migrate MissingRequiredArgumentError imports to ocp_resources.exceptions#2657
Conversation
The template_imports set in user_code_parser.py was missing "from ocp_resources.exceptions import MissingRequiredArgumentError", causing duplicate imports when regenerating resource files with --overwrite. Closes #2656
WalkthroughAdded the new template import line for MissingRequiredArgumentError (from ocp_resources.exceptions) to the class-generator parser, updated tests to cover the new import pattern, and applied a bulk, repetitive import-source refactor across many Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Report bugs in Issues Welcome! 🎉This pull request will be automatically processed with the following features: 🔄 Automatic Actions
📋 Available CommandsPR Status Management
Review & Approval
Testing & Validation
Cherry-pick Operations
Label Management
✅ Merge RequirementsThis PR will be automatically approved when the following conditions are met:
📊 Review ProcessApprovers and ReviewersApprovers:
Reviewers:
Available Labels
💡 Tips
For more information, please refer to the project documentation or contact the maintainers. |
|
/lgtm |
|
/approve |
…nto fix/issue-2656-duplicate-imports-class-generator
…nto fix/issue-2656-duplicate-imports-class-generator
There was a problem hiding this comment.
Actionable comments posted: 7
♻️ Duplicate comments (13)
ocp_resources/catalog_source.py (1)
3-4: Same import-path concern asstorage_class.py.Same pattern as
storage_class.pylines 3–4. Refer to the verification script there.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ocp_resources/catalog_source.py` around lines 3 - 4, The imports in catalog_source.py use absolute package paths like from ocp_resources.exceptions and ocp_resources.resource — mirror the fix applied in storage_class.py by switching these to relative imports (e.g., import MissingRequiredArgumentError and NamespacedResource via the module-local paths) so update the two import statements referencing MissingRequiredArgumentError and NamespacedResource to use relative module imports consistent with storage_class.py.ocp_resources/endpoints.py (1)
1-2: Same import-path concern asstorage_class.py.Same pattern as the concern raised in
storage_class.pylines 3–4. Ensureocp_resources.resourceretains the re-export ofMissingRequiredArgumentErrorfor backward compatibility.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ocp_resources/endpoints.py` around lines 1 - 2, The endpoints import indicates other modules expect MissingRequiredArgumentError to be re-exported from ocp_resources.resource for backward compatibility; update ocp_resources/resource.py to re-export MissingRequiredArgumentError (e.g., import MissingRequiredArgumentError from .exceptions and include it in the module exports/__all__) so callers that import MissingRequiredArgumentError via ocp_resources.resource (alongside NamespacedResource) continue to work without changing their import paths.ocp_resources/application_aware_cluster_resource_quota.py (1)
5-6: Same import-path concern asstorage_class.py.Same pattern as
storage_class.pylines 3–4. Refer to the verification script there.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ocp_resources/application_aware_cluster_resource_quota.py` around lines 5 - 6, The top-level imports use absolute import paths like "from ocp_resources.exceptions import MissingRequiredArgumentError" and "from ocp_resources.resource import Resource"; change them to the same relative import style used in storage_class.py (e.g., "from ..exceptions import MissingRequiredArgumentError" and "from ..resource import Resource") so the module resolution matches the package layout and the verification script expectations.ocp_resources/image_caching_internal_knative_dev.py (1)
5-6: Same generated-code verification concern as above.This file is also marked generated; please ensure this import change comes from the generator/template flow.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ocp_resources/image_caching_internal_knative_dev.py` around lines 5 - 6, The import change adding MissingRequiredArgumentError alongside NamespacedResource appears to be a manual edit in generated code; revert this manual change or update the code generator/template so the generator emits "from ocp_resources.exceptions import MissingRequiredArgumentError" consistently; ensure the generator/template that produces ocp_resources/image_caching_internal_knative_dev.py is updated and the repository regeneration step is run so the added symbol (MissingRequiredArgumentError) is present via the generator rather than as a one-off local edit referencing NamespacedResource and MissingRequiredArgumentError.ocp_resources/authorino.py (1)
6-7: Duplicate: generated-code change should come from generator.This import change appears inside generated code and should be produced through generator/template updates.
As per coding guidelines: "If someone modifies generated code directly, flag it as a violation - changes should be made to the class-generator instead."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ocp_resources/authorino.py` around lines 6 - 7, This change adds or alters imports (MissingRequiredArgumentError, NamespacedResource) directly in generated file authorino.py; revert the manual edit in ocp_resources/authorino.py and instead update the generator/template that produces this file (the class-generator) so the import change is emitted by code generation rather than modifying the generated module directly.ocp_resources/ssp.py (1)
6-7: Duplicate of generated-file source-of-truth issue.This is another generated-file import edit that should be made via generator/template and then regenerated.
As per coding guidelines: "If someone modifies generated code directly, flag it as a violation - changes should be made to the class-generator instead."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ocp_resources/ssp.py` around lines 6 - 7, This change is a direct edit to generated imports (MissingRequiredArgumentError, NamespacedResource) in the generated module; revert the manual modification and apply the fix in the generation template/class-generator instead, then regenerate the file so the import lines are produced by the generator; ensure the generator/template emits the correct imports (including MissingRequiredArgumentError and NamespacedResource) to avoid future drift.ocp_resources/group.py (1)
6-7: Same generated-code edit concern as above.This import change is also inside a generated file block and should come from generator/template regeneration, not direct file edits.
As per coding guidelines: "If someone modifies generated code directly, flag it as a violation - changes should be made to the class-generator instead."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ocp_resources/group.py` around lines 6 - 7, The change to imports in ocp_resources/group.py (the import of MissingRequiredArgumentError and Resource) is inside generated code and must not be edited directly; revert the manual edits in this file and instead update the class-generator/template that produces ocp_resources.group so the generated output includes the correct imports (referencing the symbols MissingRequiredArgumentError and Resource), then re-run the generator to regenerate ocp_resources/group.py.ocp_resources/model_registry_modelregistry_opendatahub_io.py (1)
6-7: Duplicate of generated-file edit issue.As with the other generated resources, this import change should come from generator/template source and regeneration.
As per coding guidelines: "If someone modifies generated code directly, flag it as a violation - changes should be made to the class-generator instead."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ocp_resources/model_registry_modelregistry_opendatahub_io.py` around lines 6 - 7, This change modifies generated imports (MissingRequiredArgumentError and NamespacedResource) directly in the generated resource module; revert the manual edit in ocp_resources.model_registry_modelregistry_opendatahub_io.py and instead update the generator/template that emits these imports so regeneration produces the intended import lines; locate the generator/template that emits the import block for the ModelRegistry resource (the class-generator that defines how MissingRequiredArgumentError and NamespacedResource are imported) and apply the fix there, then regenerate the file rather than committing edits to the generated output.ocp_resources/cluster_role.py (1)
1-2: Same import pattern change asreclaim_space_cron_job.py.The backward-compatibility concern about
ocp_resources.resourcere-exportingMissingRequiredArgumentErrorapplies here equally. See the verification script in thereclaim_space_cron_job.pycomment.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ocp_resources/cluster_role.py` around lines 1 - 2, The import of MissingRequiredArgumentError was changed to come from ocp_resources.exceptions which breaks backward compatibility with code that expects the symbol to be re-exported from ocp_resources.resource; update the imports in cluster_role.py to import MissingRequiredArgumentError from ocp_resources.resource (e.g., from ocp_resources.resource import Resource, MissingRequiredArgumentError) and remove the direct import from ocp_resources.exceptions so the module continues to re-export the exception as before.ocp_resources/reclaim_space_job.py (1)
3-4: Same import pattern change asreclaim_space_cron_job.py.The backward-compatibility concern about
ocp_resources.resourcere-exportingMissingRequiredArgumentErrorapplies here equally. See the verification script in thereclaim_space_cron_job.pycomment.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ocp_resources/reclaim_space_job.py` around lines 3 - 4, Ensure MissingRequiredArgumentError is imported directly from ocp_resources.exceptions (not via ocp_resources.resource) to avoid relying on a re-export; if you find any import like "from ocp_resources.resource import MissingRequiredArgumentError" change it to "from ocp_resources.exceptions import MissingRequiredArgumentError" while keeping NamespacedResource imported from ocp_resources.resource (verify similar change applied as in reclaim_space_cron_job.py).ocp_resources/csi_storage_capacity.py (1)
1-2: Same import pattern change asnetwork_attachment_definition.py.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ocp_resources/csi_storage_capacity.py` around lines 1 - 2, The imports in csi_storage_capacity.py use absolute package imports but should follow the same pattern as network_attachment_definition.py; change the two import lines to use relative imports for MissingRequiredArgumentError and NamespacedResource (i.e., import MissingRequiredArgumentError from .exceptions and NamespacedResource from .resource) so the module uses the consistent local-relative import style.ocp_resources/ip_address_pool.py (1)
3-4: Same import pattern change asnetwork_attachment_definition.py.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ocp_resources/ip_address_pool.py` around lines 3 - 4, The imports in ip_address_pool.py should follow the same pattern used in network_attachment_definition.py: replace the current top-level imports "from ocp_resources.exceptions import MissingRequiredArgumentError" and "from ocp_resources.resource import NamespacedResource" with the consistent import style used elsewhere (e.g., use relative imports such as "from .exceptions import MissingRequiredArgumentError" and "from .resource import NamespacedResource" or the project's agreed absolute/relative form), updating the import statements for the symbols MissingRequiredArgumentError and NamespacedResource so they match the pattern used in network_attachment_definition.py.ocp_resources/role.py (1)
3-4: Same import pattern change asnetwork_attachment_definition.py.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ocp_resources/role.py` around lines 3 - 4, Update the import pattern in role.py to match network_attachment_definition.py by using relative imports: replace "from ocp_resources.exceptions import MissingRequiredArgumentError" with "from .exceptions import MissingRequiredArgumentError" and "from ocp_resources.resource import NamespacedResource" with "from .resource import NamespacedResource" so the module imports MissingRequiredArgumentError and NamespacedResource via package-relative imports.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@class_generator/tests/test_user_code_parser.py`:
- Around line 208-245: The test reveals parse_user_code_from_file incorrectly
treats mixed imports (e.g., "from ocp_resources.exceptions import
ExecOnPodError, MissingRequiredArgumentError") as user imports because it
matches exact import string; update parse_user_code_from_file to normalize and
compare import targets rather than raw lines: parse import statements (both
"import X" and "from Y import A, B") into module and symbol names and filter out
any symbols/modules that appear in the template import set (handle
comma-separated names and whitespace), ensuring template imports like
NamespacedResource, MissingRequiredArgumentError, and typing.Any are removed
even when bundled with other imports; reference the function
parse_user_code_from_file and ensure user_imports output is built from the
filtered, normalized imports.
In `@ocp_resources/cluster_resource_quota.py`:
- Around line 6-7: The edits touch a generated region and must not be patched
directly—revert any direct changes in the generated file and instead update the
class-generator templates/sources that produce the import block (the generator
that emits the imports for MissingRequiredArgumentError and Resource), then
re-run the generation step so ocp_resources cluster resource quota output is
regenerated; do not manually edit the generated region in the file.
In `@ocp_resources/config_imageregistry_operator_openshift_io.py`:
- Around line 6-7: This change was made directly in generated output
(ocp_resources/config_imageregistry_operator_openshift_io.py); revert this edit
in the generated file, then update the class-generator template/source that
produces the imports so the desired import (from ocp_resources.exceptions import
MissingRequiredArgumentError and from ocp_resources.resource import Resource) is
emitted by the generator, and re-run the generator to regenerate
ocp_resources/config_imageregistry_operator_openshift_io.py; ensure you do not
leave manual edits inside the generated-markers region so the repository adheres
to the rule about not modifying generated code.
In `@ocp_resources/deployment.py`:
- Around line 7-8: The imports in ocp_resources/deployment.py were edited inside
a generated block; revert the manual edits in deployment.py (restoring the
original generated import block referencing MissingRequiredArgumentError and
NamespacedResource) and instead make the change in the class-generator
source/template that produces deployment.py, then regenerate the ocp_resources
artifacts; locate the generated block responsible for the Deployment
class/headers (related to NamespacedResource and MissingRequiredArgumentError)
in the class-generator and apply the intended modification there so subsequent
runs produce the corrected imports.
In `@ocp_resources/pod.py`:
- Around line 9-11: The import changes for ExecOnPodError,
MissingRequiredArgumentError, Node and NamespacedResource are inside generated
code and must not be hand-edited; instead update the class-generator/template
that emits ocp_resources/pod.py to include these imports (or adjust the
template's import block) and then re-generate the file so the generated block
contains the correct imports rather than modifying the generated lines directly.
In `@ocp_resources/storage_class.py`:
- Around line 3-4: The import of MissingRequiredArgumentError should be reverted
to follow the project convention: replace the current import from
ocp_resources.exceptions with importing MissingRequiredArgumentError from
ocp_resources.resource so that the top of the file imports Resource and
MissingRequiredArgumentError from the same module; update the import statement
that currently references MissingRequiredArgumentError to use
ocp_resources.resource and keep the Resource import unchanged.
In `@ocp_resources/volume_snapshot.py`:
- Around line 6-7: The imports in ocp_resources/volume_snapshot.py
(MissingRequiredArgumentError, NamespacedResource) were modified directly in
generated code; revert any manual edits and apply the import-source change to
the code generator/template that produces this file (the generator that emits
the class using NamespacedResource and MissingRequiredArgumentError) and then
regenerate the resource so the change is persistent and not overwritten by
future generations.
---
Duplicate comments:
In `@ocp_resources/application_aware_cluster_resource_quota.py`:
- Around line 5-6: The top-level imports use absolute import paths like "from
ocp_resources.exceptions import MissingRequiredArgumentError" and "from
ocp_resources.resource import Resource"; change them to the same relative import
style used in storage_class.py (e.g., "from ..exceptions import
MissingRequiredArgumentError" and "from ..resource import Resource") so the
module resolution matches the package layout and the verification script
expectations.
In `@ocp_resources/authorino.py`:
- Around line 6-7: This change adds or alters imports
(MissingRequiredArgumentError, NamespacedResource) directly in generated file
authorino.py; revert the manual edit in ocp_resources/authorino.py and instead
update the generator/template that produces this file (the class-generator) so
the import change is emitted by code generation rather than modifying the
generated module directly.
In `@ocp_resources/catalog_source.py`:
- Around line 3-4: The imports in catalog_source.py use absolute package paths
like from ocp_resources.exceptions and ocp_resources.resource — mirror the fix
applied in storage_class.py by switching these to relative imports (e.g., import
MissingRequiredArgumentError and NamespacedResource via the module-local paths)
so update the two import statements referencing MissingRequiredArgumentError and
NamespacedResource to use relative module imports consistent with
storage_class.py.
In `@ocp_resources/cluster_role.py`:
- Around line 1-2: The import of MissingRequiredArgumentError was changed to
come from ocp_resources.exceptions which breaks backward compatibility with code
that expects the symbol to be re-exported from ocp_resources.resource; update
the imports in cluster_role.py to import MissingRequiredArgumentError from
ocp_resources.resource (e.g., from ocp_resources.resource import Resource,
MissingRequiredArgumentError) and remove the direct import from
ocp_resources.exceptions so the module continues to re-export the exception as
before.
In `@ocp_resources/csi_storage_capacity.py`:
- Around line 1-2: The imports in csi_storage_capacity.py use absolute package
imports but should follow the same pattern as network_attachment_definition.py;
change the two import lines to use relative imports for
MissingRequiredArgumentError and NamespacedResource (i.e., import
MissingRequiredArgumentError from .exceptions and NamespacedResource from
.resource) so the module uses the consistent local-relative import style.
In `@ocp_resources/endpoints.py`:
- Around line 1-2: The endpoints import indicates other modules expect
MissingRequiredArgumentError to be re-exported from ocp_resources.resource for
backward compatibility; update ocp_resources/resource.py to re-export
MissingRequiredArgumentError (e.g., import MissingRequiredArgumentError from
.exceptions and include it in the module exports/__all__) so callers that import
MissingRequiredArgumentError via ocp_resources.resource (alongside
NamespacedResource) continue to work without changing their import paths.
In `@ocp_resources/group.py`:
- Around line 6-7: The change to imports in ocp_resources/group.py (the import
of MissingRequiredArgumentError and Resource) is inside generated code and must
not be edited directly; revert the manual edits in this file and instead update
the class-generator/template that produces ocp_resources.group so the generated
output includes the correct imports (referencing the symbols
MissingRequiredArgumentError and Resource), then re-run the generator to
regenerate ocp_resources/group.py.
In `@ocp_resources/image_caching_internal_knative_dev.py`:
- Around line 5-6: The import change adding MissingRequiredArgumentError
alongside NamespacedResource appears to be a manual edit in generated code;
revert this manual change or update the code generator/template so the generator
emits "from ocp_resources.exceptions import MissingRequiredArgumentError"
consistently; ensure the generator/template that produces
ocp_resources/image_caching_internal_knative_dev.py is updated and the
repository regeneration step is run so the added symbol
(MissingRequiredArgumentError) is present via the generator rather than as a
one-off local edit referencing NamespacedResource and
MissingRequiredArgumentError.
In `@ocp_resources/ip_address_pool.py`:
- Around line 3-4: The imports in ip_address_pool.py should follow the same
pattern used in network_attachment_definition.py: replace the current top-level
imports "from ocp_resources.exceptions import MissingRequiredArgumentError" and
"from ocp_resources.resource import NamespacedResource" with the consistent
import style used elsewhere (e.g., use relative imports such as "from
.exceptions import MissingRequiredArgumentError" and "from .resource import
NamespacedResource" or the project's agreed absolute/relative form), updating
the import statements for the symbols MissingRequiredArgumentError and
NamespacedResource so they match the pattern used in
network_attachment_definition.py.
In `@ocp_resources/model_registry_modelregistry_opendatahub_io.py`:
- Around line 6-7: This change modifies generated imports
(MissingRequiredArgumentError and NamespacedResource) directly in the generated
resource module; revert the manual edit in
ocp_resources.model_registry_modelregistry_opendatahub_io.py and instead update
the generator/template that emits these imports so regeneration produces the
intended import lines; locate the generator/template that emits the import block
for the ModelRegistry resource (the class-generator that defines how
MissingRequiredArgumentError and NamespacedResource are imported) and apply the
fix there, then regenerate the file rather than committing edits to the
generated output.
In `@ocp_resources/reclaim_space_job.py`:
- Around line 3-4: Ensure MissingRequiredArgumentError is imported directly from
ocp_resources.exceptions (not via ocp_resources.resource) to avoid relying on a
re-export; if you find any import like "from ocp_resources.resource import
MissingRequiredArgumentError" change it to "from ocp_resources.exceptions import
MissingRequiredArgumentError" while keeping NamespacedResource imported from
ocp_resources.resource (verify similar change applied as in
reclaim_space_cron_job.py).
In `@ocp_resources/role.py`:
- Around line 3-4: Update the import pattern in role.py to match
network_attachment_definition.py by using relative imports: replace "from
ocp_resources.exceptions import MissingRequiredArgumentError" with "from
.exceptions import MissingRequiredArgumentError" and "from
ocp_resources.resource import NamespacedResource" with "from .resource import
NamespacedResource" so the module imports MissingRequiredArgumentError and
NamespacedResource via package-relative imports.
In `@ocp_resources/ssp.py`:
- Around line 6-7: This change is a direct edit to generated imports
(MissingRequiredArgumentError, NamespacedResource) in the generated module;
revert the manual modification and apply the fix in the generation
template/class-generator instead, then regenerate the file so the import lines
are produced by the generator; ensure the generator/template emits the correct
imports (including MissingRequiredArgumentError and NamespacedResource) to avoid
future drift.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (66)
class_generator/parsers/user_code_parser.pyclass_generator/tests/test_user_code_parser.pyocp_resources/application_aware_cluster_resource_quota.pyocp_resources/application_aware_resource_quota.pyocp_resources/authorino.pyocp_resources/catalog_source.pyocp_resources/cluster_resource_quota.pyocp_resources/cluster_role.pyocp_resources/cluster_role_binding.pyocp_resources/cluster_user_defined_network.pyocp_resources/config_imageregistry_operator_openshift_io.pyocp_resources/controller_revision.pyocp_resources/cron_job.pyocp_resources/csi_storage_capacity.pyocp_resources/data_import_cron.pyocp_resources/data_source.pyocp_resources/deployment.pyocp_resources/dsc_initialization.pyocp_resources/endpoint_slice.pyocp_resources/endpoints.pyocp_resources/fence_agent_remediation_templates.pyocp_resources/group.pyocp_resources/image_caching_internal_knative_dev.pyocp_resources/image_digest_mirror_set.pyocp_resources/inference_graph.pyocp_resources/inference_service.pyocp_resources/ip_address_pool.pyocp_resources/limit_range.pyocp_resources/llama_stack_distribution.pyocp_resources/lm_eval_job.pyocp_resources/mig_analytic.pyocp_resources/mig_cluster.pyocp_resources/mig_migration.pyocp_resources/model_registry.pyocp_resources/model_registry_modelregistry_opendatahub_io.pyocp_resources/multi_cluster_observability.pyocp_resources/multi_network_policy.pyocp_resources/network_attachment_definition.pyocp_resources/node_health_check.pyocp_resources/performance_profile.pyocp_resources/pod.pyocp_resources/pod_metrics.pyocp_resources/reclaim_space_cron_job.pyocp_resources/reclaim_space_job.pyocp_resources/replica_set.pyocp_resources/resource_quota.pyocp_resources/restore.pyocp_resources/role.pyocp_resources/sealed_secret.pyocp_resources/security_context_constraints.pyocp_resources/service_mesh_member.pyocp_resources/serving_runtime.pyocp_resources/snapshot.pyocp_resources/ssp.pyocp_resources/storage_class.pyocp_resources/trustyai_service.pyocp_resources/user.pyocp_resources/user_defined_network.pyocp_resources/virtual_machine_clone.pyocp_resources/virtual_machine_cluster_instancetype.pyocp_resources/virtual_machine_export.pyocp_resources/virtual_machine_instance_preset.pyocp_resources/virtual_machine_instance_replica_set.pyocp_resources/virtual_machine_instancetype.pyocp_resources/volume_snapshot.pyocp_resources/volume_snapshot_class.py
✅ Files skipped from review due to trivial changes (5)
- ocp_resources/replica_set.py
- ocp_resources/user_defined_network.py
- ocp_resources/inference_graph.py
- ocp_resources/cluster_user_defined_network.py
- ocp_resources/model_registry.py
🚧 Files skipped from review as they are similar to previous changes (1)
- class_generator/parsers/user_code_parser.py
|
/verified |
|
review again; all comments addressed. |
|
🧠 Learnings used✅ Actions performedReview triggered.
|
REVIEW and approve |
|
Tip For best results, initiate chat on the files or code changes.
However, this PR
The old learning is now obsolete and contradicts the new project standard. Before I approve this PR, please confirm:
Once you confirm, I'll remove the outdated learning and approve the PR. 🧠 Learnings used |
@coderabbitai, yes. All exception should be imported from exception. |
What this PR does
Class generator fix: Adds
from ocp_resources.exceptions import MissingRequiredArgumentErrorto thetemplate_importsset inclass_generator/parsers/user_code_parser.py, so the parser recognizes it as a template import during regeneration.Resource import migration: Migrates all 63 resource files from importing
MissingRequiredArgumentErrorviaocp_resources.resource(where it's also imported for internal use) to importing directly from the canonical sourceocp_resources.exceptions. This eliminates ruff F811 errors when both import lines appeared in the same file.Test coverage: Adds and updates tests to cover the new import pattern.
Why we need it
MissingRequiredArgumentErroris defined inocp_resources.exceptions. Resource files were importing it fromocp_resources.resource(where it's also imported for internal use), causing ruff F811 (redefinition of unused name) when both import lines appeared in the same file. This PR standardizes all resource files to import from the canonical source.Which issue(s) this PR fixes
Closes #2656
Changes
class_generator/parsers/user_code_parser.py— added exceptions import to template_importsclass_generator/tests/test_user_code_parser.py— added test for exceptions import, updated test for new import styleocp_resources/*.pyfiles — migrated MissingRequiredArgumentError import to ocp_resources.exceptionsTest plan
test_parse_file_with_exceptions_importto verify the new import pattern is recognized as a template importtest_parse_file_with_different_template_importsto reflect the new separate import styleruff check ocp_resources/ --select F811returns zero errors